#include "Import/BDFImport/BulkData/Element/CONM2Parser.h"

#include "gtest/gtest.h"

#include "DataStructure/Common/Constant.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"

using SG::DataStructure::Common::TOLERANCE;
using namespace SG::DataStructure::FEM;
#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;

extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class CONM2ParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (CONM2ParserTest, ParseEntry_Basic)
{
    std::vector<std::string> Entry = { "CONM2    999     999     0       .0906   0.      0.      0.",
                                       "         .35     0.      .56     0.      0.      .07" };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);

    auto status = SG::Import::BDF::BULKDATA::ParseCONM2 (DB_SERVICEFACTORY, dividedEntryInfo);

    ASSERT_EQ (status, SG::DataStructure::Common::Status::STATUS_Success);

    SG::DataStructure::FEM::CONM2Data data;
    ASSERT_EQ (DB_SERVICEFACTORY->get<IElementService> ()->FindById (999, data), SG::DataStructure::Common::Status::STATUS_Success);

    ASSERT_EQ (data.m_id, 999);
    ASSERT_EQ (data.m_g[0], 999);
    ASSERT_EQ (data.m_cId, 0);
    ASSERT_NEAR (data.m_mass, 0.0906, TOLERANCE);

    ASSERT_NEAR (data.m_x[0], 0.0, TOLERANCE);
    ASSERT_NEAR (data.m_x[1], 0.0, TOLERANCE);
    ASSERT_NEAR (data.m_x[2], 0.0, TOLERANCE);

    // 惯性矩分配方式
    ASSERT_NEAR (data.m_I1[0], 0.35, TOLERANCE);  // I11
    ASSERT_NEAR (data.m_I2[0], 0.0, TOLERANCE);   // I21
    ASSERT_NEAR (data.m_I2[1], 0.56, TOLERANCE);  // I22
    ASSERT_NEAR (data.m_I3[0], 0.0, TOLERANCE);   // I31
    ASSERT_NEAR (data.m_I3[1], 0.0, TOLERANCE);   // I32
    ASSERT_NEAR (data.m_I3[2], 0.07, TOLERANCE);  // I33
}